#!/usr/bin/perl

use strict;
use DBI;

my $dbdriver = 'SQLite';	#Name of the DBD
my $dbfile   = 'test.db';	#Name of DB file.

#Check that SQLite DBD is available, else exit with error.
die "$dbdriver driver does not exist\n" unless grep {/$dbdriver/i} DBI->available_drivers();

my $dbh = DBI->connect("dbi:$dbdriver:dbname=$dbfile","","",{ RaiseError => 1 },) or die $DBI::errstr;
$dbh->{AutoCommit} = 0;		#No update of DB before commit.

#Create the DB file and create the table
my $sth_ct = $dbh->prepare("CREATE TABLE IF NOT EXISTS t1 (ID INTEGER PRIMARY KEY DESC, Name STRING, Salary INTEGER)");
$sth_ct->execute();

#insert records
my $sth_insert = $dbh->prepare("INSERT INTO t1 (Name, Salary) VALUES (?, ?)");		#Statement with 2 parameters.
$sth_insert->execute("Mohsen Islam", 15);
$sth_insert->execute("Ahmad Mohsen", 16);
$sth_insert->execute("Mohamed Mohsen", 17);
$sth_insert->execute("Mohsen Kamal", 15);
$sth_insert->execute("Yousf Mohsen", 16);
$sth_insert->execute("Mina Mohsen", 15);

$dbh->commit;
#$dbh->rollback;


my @row;

my $sth = $dbh->prepare("SELECT * FROM t1");

$sth->execute();
while ( @row = $sth->fetchrow_array ) {
   print "Name: @row[1] \tSalary: @row[2]\n";
}

$dbh->disconnect;